package com.hua.demo03.service.impl;

import com.hua.demo03.dao.UserMapper;
import com.hua.demo03.pojo.MyUserDetails;
import com.hua.demo03.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyUserServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = null;
        user = userMapper.getUserByName(username);
        if (user == null) {
            throw new UsernameNotFoundException(username+"用户名错误");
        }
        return new MyUserDetails(user);
    }
}
